package com.zazu.mycl.application.terminal;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Window;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.text.Caret;

import com.zazu.mycl.application.ApplicationController;
import com.zazu.mycl.application.CommandRunner;
import com.zazu.mycl.application.DefaultCommandRunner;

public class MyClInput extends JPanel{

	MyClInput(JFrame parentWindow)
	{
		textInput = new JTextArea();
		
		
		JScrollPane myScroll = new JScrollPane(textInput,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		
		cr = new DefaultCommandRunner(ApplicationController.getCommandMappings(), textInput, parentWindow);
		
		textInput.addKeyListener(new MyClInputKeyHandler(cr));
		
		this.setFocusable(false);
		
		this.setLayout(new BorderLayout());
		this.add(myScroll, BorderLayout.CENTER);
		this.setBorder(BorderFactory.createEmptyBorder());
		
		setInputStyles();

		textInput.setFocusable(true);
		textInput.requestFocus(true);
		textInput.addInputMethodListener(new MyClInputMethodHandler());
		textInput.enableInputMethods(true);
	}
	
	public void setInputStyles()
	{
		textInput.setAutoscrolls(true);
		textInput.setBorder(BorderFactory.createEmptyBorder());
		textInput.setBackground(Color.BLACK);
		Font myFont = new Font(Font.MONOSPACED, Font.BOLD, 12);
		textInput.setForeground(Color.WHITE);
		textInput.setFont(myFont);
		textInput.setLineWrap(true);
		
		Caret myCaret = textInput.getCaret();
		myCaret.setVisible(true);
		textInput.setCaretColor(Color.GRAY);
		textInput.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
		
	}
	
	private JTextArea textInput;
	private CommandRunner cr;
}
